﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Coolite.Ext.Web;
using GUESTSMANAGEMENT.Controller;

namespace GUESTSMANAGEMENT.View.Report
{
    public partial class gridDetailReport : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void EnventDateSelected(object sender, EventArgs e)
        {
            using (guestsmanagementEntities context = new guestsmanagementEntities())
            {
                try
                {
                    DateTime date = this.eventDate.SelectedDate;
                    gmevent evento = Controller.Event.getByEventDate(date);

                    if (evento != null)
                    {
                        //int cdUser = Convert.ToInt32(Session["userCd"]);
                        var selectListGuests = from guestlists in context.gmlistguests.Include("gmlistguests.cdlistguests")
                                               from gevent in context.gmevent.Include("gmevent.nmevent")
                                               from user in context.gmuser.Include("gmuser.nmuser")
                                               where guestlists.GMUSER_CDUSER == user.CDUSER && gevent.CDEVENT == guestlists.GMEVENT_CDEVENT
                                               && gevent.DTEVENT == date
                                               select new
                                                   {
                                                       user.NMUSER,
                                                       guestlists.NMGUEST,
                                                       guestlists.TMCONFIRM,
                                                       guestlists.FGTYPEINVITE,
                                                       gevent.NMEVENT,
                                                       gevent.DTEVENT
                                                   };

                        var lista = selectListGuests.ToList();
                        
                        this.reportDetailStore.DataSource = lista;
                        this.reportDetailStore.DataBind();

                        this.eventName.Text = evento.NMEVENT;
                        this.reportGridPanel.Enabled = true;
                    }
                    else
                    {
                        Ext.Msg.Alert("Alerta!", "Não há eventos cadastros nesta data!").Show();
                        this.reportGridPanel.Reload();
                    }
                }
                catch
                {
                    Ext.Msg.Alert("Alerta!", "Ocorreu um erro durante a transação! Tente novamente!").Show();
                }
            }
        }
    }
}